#include <ctime>
#include <ros/ros.h>
#include "turtlesim/Spawn.h"
#include "turtlesim/Kill.h"
#include <string.h>
#include <stdlib.h>
int main(int argc, char** argv)
{
	if (argc != 3)
	{
		ROS_INFO("rosrun cmd turtlr_on_off spawn/kill name");
		return -1;
	}
    // 初始化ROS节点
	ros::init(argc, argv, "turtle_client");

    // 创建节点句柄
	ros::NodeHandle node;

	srand((int)time(0));
	if (!strcmp(argv[1],"spawn"))
	{
		ROS_INFO("spawn");
		 // 发现/spawn服务后，创建一个服务客户端，连接名为/spawn的service
		ros::service::waitForService("/spawn");
		ros::ServiceClient person_client = node.serviceClient<turtlesim::Spawn>("/spawn");

		turtlesim::Spawn srv;
		srv.request.x=rand()%10+(rand()%10)*0.1;
		srv.request.y=rand()%10+(rand()%10)*0.1;
		srv.request.name=argv[2];

		person_client.call(srv);

		// 显示服务调用结果
		ROS_INFO("Show person result : %s", srv.response.name.c_str());
	}
	else if (!strcmp(argv[1],"kill"))
	{
		ROS_INFO("kill");

        ros::service::waitForService("/kill");
        ros::ServiceClient person_client = node.serviceClient<turtlesim::Kill>("/kill");

        turtlesim::Kill srv;

        srv.request.name=argv[2];

        person_client.call(srv);

        // 显示服务调用结果
	}
	return 0;
};


